//
//  PjSip.h
//  Sip
//
//  Created by Erphan on 12/20/10.
//  Copyright 2010 Smonte. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <AudioToolbox/AudioToolbox.h>
#include <pjsua-lib/pjsua.h>
#include "Constants.h"

@class SipManager;


typedef struct app_config_struct
{
	pjsua_config cfg;
	pjsua_media_config media_cfg;
	pjsua_logging_config log_cfg;
	
	pjsua_transport_config transport_cfg;
	pjsua_transport_config rtp_cfg;
	
	SystemSoundID ring_id;
	CFRunLoopTimerRef ring_timer;
	
	int ringback_slot;
	int ring_slot;
	int ringback_cnt;
	int ring_cnt;
	
	pjmedia_port *ring_port;
	pjmedia_port *ringback_port;
	
	pj_bool_t ringback_on;
	pj_bool_t ring_on;
	
} app_config_struct;

struct my_call_data
{
	pj_pool_t          *pool;
	pjmedia_port       *tonegen;
	pjsua_conf_port_id  toneslot;
};

@interface PjSip : NSObject {
@private
	NSString *sipDomain;
	NSString *sipUserName;
	NSString *sipPassword;
	pjsua_acc_id acc_id;
	SipManager *manager;
}

@property (nonatomic, retain) NSString *sipDomain;
@property (nonatomic, retain) NSString *sipUserName;
@property (nonatomic, retain) NSString *sipPassword;

- (id)initWithManager:(SipManager *)_manager;
- (BOOL)initializePJ;
- (BOOL)connect;
- (void)disconnect;
- (BOOL)removeAccount;
- (BOOL)makeCall:(NSString *)number :(int *)callId;
- (BOOL)answerCall:(int)callId;
- (BOOL)hangup:(int)callId;
- (BOOL)declineCall:(int)callId;
- (BOOL)playDTMF:(NSNumber *)callId :(pj_str_t *)digits;
- (BOOL)setMute:(BOOL)enable;
- (BOOL)setHoldEnabled: (BOOL)enable :(int)call_id;
- (BOOL)setSpeakerPhoneEnabled:(BOOL)enable;
- (void)showRegistrationStatus;
- (int)getSipStatus;
@end
